<template>
  <div class="container">
    <div class="top">
      <el-input
        style="width:300px"
        :disabled="true"
        placeholder="请搜索商品信息"
        v-model="commodityNameList.name"
      >
        <template slot="prepend">商品</template>
        <el-button slot="append" icon="el-icon-search" @click="commodityBtn"></el-button>
      </el-input>
      <el-select
            
            :multiple="false"
            filterable
            remote
            center
            reserve-keyword
            v-model="selectList"
            placeholder="请搜索选择配送中心"
            :remote-method="selectListsRemoteMethod"
            :loading="selectLists.loading"
          >
            <el-option
              v-for="item in selectLists.option"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
      <el-button
        size="small"
        type="primary"
        class="handleSearch"
        icon="el-icon-search"
        @click="handleSearch()"
      >查询</el-button>
       <el-button
        size="small"
        type="danger"
        class="handleSearch"
        icon="el-icon-delete"
        @click="empty()"
      >清空</el-button>
    </div>
    <el-table max-height="600" :data="tableData" border style="width: 100%" empty-text="暂无数据">
      <el-table-column prop="erp_goods_code" label="商品code" align="center"></el-table-column>
      <el-table-column prop="goods_name" label="商品名称" align="center"></el-table-column>
      <el-table-column prop="unit" label="商品单位" align="center"></el-table-column>
      <el-table-column prop="spec" label="商品规格" align="center"></el-table-column>
      <el-table-column prop="all_stock_num" label="剩余库存" align="center"></el-table-column>
      <el-table-column prop="all_stock_qty" label="剩余箱数" align="center"></el-table-column>
      <el-table-column prop="all_stock_amount" label="总价值" align="center"></el-table-column>
      <el-table-column prop="dcname" label="配送中心名字" align="center"></el-table-column>
        <el-table-column prop="whsename" label=" 仓库名字"  align="center"></el-table-column>
      <el-table-column label="操作" width="300" align="center">
        <template slot-scope="scope">
          <el-button size="mini" icon="el-icon-edit" type="primary" @click="handleEdit(scope)">高退低进</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination @page="handleSizeChange" @pagesize="handleCurrentChange" :pageData="pageData"></pagination>
    <!-- 选择商品搜索dialog -->
    <storthDialog :commoditydialog="commoditydialog" @tag="commodityTag"></storthDialog>
    <!-- 详情dialog -->
    <stockinfoDialog :dialog="dialog" @upData="getData"></stockinfoDialog>
  </div>
</template>
<script>
import Pagination from "@/components/pagination";
import { getstockIndex } from "@/api/stockHeight/stockhei";
import StorthDialog from "@/components/stockReturnDialog/storthDialog";
import StockinfoDialog from "@/components/stockReturnDialog/stockinfoDialog";
import { selectRdcData } from "@/api/select/select";
export default {
  components: {
    pagination: Pagination,
    storthDialog: StorthDialog,
    stockinfoDialog: StockinfoDialog
  },
  data() {
    return {
      //dialog信息
      commoditydialog: {
        centerDialogVisible: false
      },
      commodityNameList: {
        name: "",
        code: ""
      },
      dialog: {
        centerDialogVisible: false,
        id: "",
        numprice: "",
        selectList:''
      },
      //页面数据
      tableData: [],
      //分页
      pageData: {
        pageSizes: [10, 20],
        pageSize: 10,
        page: 1,
        total: null,
        layout: "total, sizes, prev, pager, next, jumper"
      },
      search: {
        searchCode: ""
      },
       selectLists: {
        innerVisible: false,
        option: [],
        value: "",
        list: [],
        loading: false
      },
      selectList: "",
    };
  },

  created() {
    //页面数据
    this.getData();
    this.getselsetData()
  },
  methods: {
    //页面数据
    getData() {
      let data = {
        dccode_str:this.selectList,
        limit: this.pageData.pageSize,
        page: this.pageData.page,
        erp_goods_code_str: this.commodityNameList.code
      };
      getstockIndex(data)
        .then(res => {
          if (res.code == 0) {
            this.tableData = res.data.data;
            this.pageData.page = res.data.current_page;
            this.pageData.pagesize = res.data.per_page;
            this.pageData.total = res.data.total;
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    commodityTag(data) {
      this.commodityNameList = {
        name: "",
        code: ""
      };
      let arrName = [];
      let arrCode = [];
      data.forEach(res => {
        arrName.push(res.name);
        arrCode.push(res.code);
      });
      this.commodityNameList.name = arrName.join(",");
      this.commodityNameList.code = arrCode.join(",");
    },
    //超级商品搜索
    commodityBtn() {
      this.commoditydialog = {
        centerDialogVisible: true
      };
    },
    //高退低进
    handleEdit(scope) {
      this.dialog.centerDialogVisible = true;
      this.dialog.id = scope.row.erp_goods_code;
      this.dialog.numprice = scope.row.all_stock_amount;
      this.dialog.selectList = this.selectList;
    },
    // 本地搜索
    handleSearch() {
      this.pageData.page = 1;
      this.pageData.total = null;
      this.getData();
    },
    empty(){
      this.commodityNameList={
        name: "",
        code: ""
      }
    },
    getselsetData() {
      let data = {
        page: 1,
        limit: 500,
        code_or_name: this.search.selectnamecode
      };
      //获取配送中心
      selectRdcData(data).then(res => {
        if (res.data.paginate.data) {
          this.selectLists.option = res.data.paginate.data.map(item => {
            return { value: `${item.d_code}`, label: `${item.d_name}` };
          });
        }
      });
    },
    // 嵌套搜索配送方式数据
    selectListsRemoteMethod(query) {
      if (query !== "") {
        this.houseList(query);
      } else {
        this.selectLists.option = [];
      }
    },
    //获取配送数据
    houseList(query) {
      this.search.selectnamecode = query;
      this.getselsetData();
    },
    //每页多少条
    handleCurrentChange(val) {
      this.pageData.page = 1;
      this.pageData.pageSize = val;

      this.getData();
    },
    //选取页数
    handleSizeChange(page) {
      this.pageData.page = page;

      this.getData();
    },
    //选取
    handleSelectionChange(val) {
      this.multipleSelection = val;
    }
  }
};
</script>
<style scoped>
.top {
  position: relative;
}

.add {
  position: absolute;
  right: 0;
  top: 4px;
}
.pagination {
  text-align: right;
  padding: 10px;
}
</style>